package com.yanqu.road.entity.autodata.hotpotjump;

import com.alibaba.fastjson.JSONObject;
import com.yanqu.road.entity.FieldTypeAnnotation;
import com.yanqu.road.entity.autodata.AutoDataObject;

import java.math.BigDecimal;
import java.util.*;

@FieldTypeAnnotation(tableName = "t_u_activity_hotpotjump_game", desc = "火锅跳棋游戏数据")
public class UserHotpotJumpGameData extends AutoDataObject {
    @FieldTypeAnnotation(select = true, isIndex = true, update = true)
    private int activityId;
    @FieldTypeAnnotation(desc = "玩家id", select = true, isIndex = true, update = true)
    private long userId;
    @FieldTypeAnnotation(desc = "是否练习模式")
    private boolean practice;
    @FieldTypeAnnotation(desc = "回合数")
    private int round;
    @FieldTypeAnnotation(desc = "score")
    private int score;
    @FieldTypeAnnotation(desc = "火锅id")
    private int potId;
    @FieldTypeAnnotation(desc = "主角数据")
    private HotpotJumpMainRole mainRole;
    @FieldTypeAnnotation(desc = "游戏单位")
    private List<HotpotJumpUnit> units = new ArrayList<>();
    @FieldTypeAnnotation(desc = "特效格子")
    private List<HotpotJumpGrid> effectGrids = new ArrayList<>();
    @FieldTypeAnnotation(desc = "待处理的技能")
    private List<Integer> skillIds = new ArrayList<>();
    @FieldTypeAnnotation(desc = "已复活次数")
    private int reviveTimes;
    @FieldTypeAnnotation(desc = "已刷新次数")
    private int refreshTimes;
    @FieldTypeAnnotation(desc = "打到第几个BOSS了")
    private int bossIdx;
    @FieldTypeAnnotation(desc = "Boss出现的顺序")
    private List<Integer> bossIds = new ArrayList<>();
    @FieldTypeAnnotation(desc = "生成怪的唯一id用")
    private int maxUnitId;
    @FieldTypeAnnotation(desc = "当前怪物池id")
    private int unitPoolId;
    @FieldTypeAnnotation(desc = "当前怪物池还能取出来的怪")
    private List<List<Integer>> unitPoolRemain = new ArrayList<>();
    @FieldTypeAnnotation(desc = "升级在哪个阶段")
    private int gameStep;
    @FieldTypeAnnotation(desc = "暂存的连跳数")
    private int jumpAmount;


    public UserHotpotJumpGameData(int activityId, long userId) {
        this.activityId = activityId;
        this.userId = userId;
        setInsertOption();
    }

    public UserHotpotJumpGameData() {
    }

    public int getActivityId() {
        return activityId;
    }

    public void setActivityId(int activityId) {
        this.activityId = activityId;
    }

    public long getUserId() {
        return userId;
    }

    public void setUserId(long userId) {
        this.userId = userId;
    }

    public boolean isPractice() {
        return practice;
    }

    public void setPractice(boolean practice) {
        this.practice = practice;
    }

    public int getRound() {
        return round;
    }

    public void setRound(int round) {
        this.round = round;
        setUpdateOption();
    }

    public int getScore() {
        return score;
    }

    public void setScore(int score) {
        this.score = score;
        setUpdateOption();
    }

    public int getPotId() {
        return potId;
    }

    public void setPotId(int potId) {
        this.potId = potId;
    }

    public HotpotJumpMainRole getMainRole() {
        return mainRole;
    }

    public void setMainRole(HotpotJumpMainRole mainRole) {
        this.mainRole = mainRole;
    }

    public List<HotpotJumpUnit> getUnits() {
        return units;
    }

    public void setUnits(List<HotpotJumpUnit> units) {
        List<HotpotJumpUnit> tempList = new ArrayList<>();
        for (Object obj : units) {
            if (obj instanceof JSONObject) {
                HotpotJumpUnit hotpotJumpUnit = JSONObject.parseObject(obj.toString(), HotpotJumpUnit.class);
                tempList.add(hotpotJumpUnit);
            } else {
                tempList.add((HotpotJumpUnit) obj);
            }
        }
        this.units = tempList;
    }

    public List<HotpotJumpGrid> getEffectGrids() {
        return effectGrids;
    }

    public void setEffectGrids(List<HotpotJumpGrid> effectGrids) {
        List<HotpotJumpGrid> tempList = new ArrayList<>();
        for (Object obj : effectGrids) {
            if (obj instanceof JSONObject) {
                HotpotJumpGrid hotpotJumpGrid = JSONObject.parseObject(obj.toString(), HotpotJumpGrid.class);
                tempList.add(hotpotJumpGrid);
            } else {
                tempList.add((HotpotJumpGrid) obj);
            }
        }
        this.effectGrids = tempList;
    }

    public List<Integer> getSkillIds() {
        return skillIds;
    }

    public void setSkillIds(List<Integer> skillIds) {
        this.skillIds = skillIds;
    }

    public int getReviveTimes() {
        return reviveTimes;
    }

    public void setReviveTimes(int reviveTimes) {
        this.reviveTimes = reviveTimes;
    }

    public int getRefreshTimes() {
        return refreshTimes;
    }

    public void setRefreshTimes(int refreshTimes) {
        this.refreshTimes = refreshTimes;
        setUpdateOption();
    }

    public int getBossIdx() {
        return bossIdx;
    }

    public void setBossIdx(int bossIdx) {
        this.bossIdx = bossIdx;
    }

    public List<Integer> getBossIds() {
        return bossIds;
    }

    public void setBossIds(List<Integer> bossIds) {
        this.bossIds = bossIds;
    }

    public int getMaxUnitId() {
        return maxUnitId;
    }

    public void setMaxUnitId(int maxUnitId) {
        this.maxUnitId = maxUnitId;
    }

    public int getUnitPoolId() {
        return unitPoolId;
    }

    public void setUnitPoolId(int unitPoolId) {
        this.unitPoolId = unitPoolId;
    }

    public List<List<Integer>> getUnitPoolRemain() {
        return unitPoolRemain;
    }

    public void setUnitPoolRemain(List<List<Integer>> unitPoolRemain) {
        this.unitPoolRemain = unitPoolRemain;
    }

    public int getGameStep() {
        return gameStep;
    }

    public void setGameStep(int gameStep) {
        this.gameStep = gameStep;
    }

    public int getJumpAmount() {
        return jumpAmount;
    }

    public void setJumpAmount(int jumpAmount) {
        this.jumpAmount = jumpAmount;
    }

    public UserHotpotJumpGameData clone() {
        UserHotpotJumpGameData cloneData = new UserHotpotJumpGameData();
        cloneData.setPractice(practice);
        cloneData.setRound(round);
        cloneData.setScore(score);
        cloneData.setPotId(potId);
        cloneData.setMainRole(mainRole.clone());
        cloneData.setUnits(HotpotJumpUnit.cloneList(units));
        cloneData.setEffectGrids(HotpotJumpGrid.cloneList(effectGrids));
        cloneData.setSkillIds(new ArrayList<>(skillIds));
        cloneData.setReviveTimes(reviveTimes);
        cloneData.setRefreshTimes(refreshTimes);
        cloneData.setBossIdx(bossIdx);
        cloneData.setBossIds(new ArrayList<>(bossIds));
        cloneData.setMaxUnitId(maxUnitId);
        cloneData.setUnitPoolId(unitPoolId);
        for (List<Integer> list : this.unitPoolRemain) {
            cloneData.unitPoolRemain.add(new ArrayList<>(list));
        }
        cloneData.setGameStep(gameStep);
        cloneData.setJumpAmount(jumpAmount);
        return cloneData;
    }

    public void copy(UserHotpotJumpGameData data) {
        this.practice = data.practice;
        this.round = data.round;
        this.score = data.score;
        this.potId = data.potId;
        this.mainRole = data.mainRole;
        this.units = data.units;
        this.effectGrids = data.effectGrids;
        this.skillIds = data.skillIds;
        this.reviveTimes = data.reviveTimes;
        this.refreshTimes = data.refreshTimes;
        this.bossIdx = data.bossIdx;
        this.bossIds = data.bossIds;
        this.maxUnitId = data.maxUnitId;
        this.unitPoolId = data.unitPoolId;
        this.unitPoolRemain = data.unitPoolRemain;
        this.gameStep = data.gameStep;
        this.jumpAmount = data.jumpAmount;
        setUpdateOption();
    }

    public int generalUnitUniqueId() {
        return ++maxUnitId;
    }

    public void addUnit(HotpotJumpUnit unit) {
        units.add(unit);
    }
}
